<?php
/*
 * @Author: 李明
 * @Date: 2022-01-06 09:50:51
 * @LastEditTime: 2022-01-06 13:24:17
 * @LastEditors: 李明
 * @Description: 
 * @FilePath: /CRM2.0-PHP/app/Http/Resources/System.php
 * @山东壹零贰肆信息科技有限公司
 */

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class System extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
     */
    public function toArray($request)
    {
        $sytem = parent::toArray($request);
        // COMPANY=3    #0测试环境，1华鑫，2锦城，3国逸
        // INTEGER_RULES=3  # 取整方式1.向上取整，2.向下取整，3.四舍五入保留$keeps位小数(0位小数就是取整数)，4.无进位直接取整，5.无进位保留$keeps位小数
        // KEEPS=2 #保留几位小数
        try {
            $int_rules = env('INTEGER_RULES', '3');
            switch ($int_rules) {
                case '1':
                    $int_rules = "向上取整";
                    break;
                case '2':
                    $int_rules = "向下取整";
                    break;
                case '3':
                    $int_rules = "四舍五入保留" . env('KEEPS', '2') . "位小数";
                    break;
                default:
                    $int_rules = "未配置成功";
                    break;
            }
        } catch (\Throwable $th) {
            $int_rules = "未配置成功";
        }
        try { #利息规则，1：日到日  2提前一日  3延后一日
            $interest_rules = env('INTEREST_RULES', '3');
            switch ($interest_rules) {
                case '1':
                    $interest_rules = "日到日";
                    break;
                case '2':
                    $interest_rules = "提前一日";
                    break;
                case '3':
                    $interest_rules = "延后一日";
                    break;
                default:
                    $interest_rules = "未配置成功";
                    break;
            }
        } catch (\Throwable $th) {
            $interest_rules = "未配置成功";
        }
        try { #到期规则，1：日到日  2提前一日  3延后一日 
            $end_rules = env('END_RULES', '3');
            switch ($end_rules) {
                case '1':
                    $end_rules = "日到日";
                    break;
                case '2':
                    $end_rules = "提前一日";
                    break;
                case '3':
                    $end_rules = "延后一日";
                    break;
                default:
                    $end_rules = "未配置成功";
                    break;
            }
        } catch (\Throwable $th) {
            $end_rules = "未配置成功";
        }
        $sytem['int_rules'] = $int_rules;
        $sytem['end_rules'] = $end_rules;
        $sytem['interest_rules'] = $interest_rules;
        return $sytem;
    }
}
